'''
Author: bodhi
Date: 2025-05-09 12:15:20
LastEditors: bodhi
LastEditTime: 2025-05-19 18:11:44
'''
import sys
from pathlib import Path
from utils.submission_checker import SubmissionChecker
from utils.logger import setup_logger

def main():
    if len(sys.argv) != 4:
        print("Usage: python check_submissions.py <excel_file> <homework_dir> <output_dir>")
        sys.exit(1)

    excel_path = Path(sys.argv[1])
    homework_dir = Path(sys.argv[2])
    output_dir = Path(sys.argv[3])

    # 设置日志
    logger = setup_logger(output_dir)
    logger.info("开始检查作业提交情况")
    logger.info(f"Excel文件: {excel_path}")
    logger.info(f"作业目录: {homework_dir}")
    logger.info(f"输出目录: {output_dir}")

    try:
        # 创建输出目录
        output_dir.mkdir(parents=True, exist_ok=True)

        # 初始化检查器
        checker = SubmissionChecker(excel_path, homework_dir, output_dir)

        # 检查提交情况
        report, _ = checker.check_submissions()

        # 保存报告
        report_path = output_dir / "submission_report.txt"
        checker.save_report(report, report_path)

        # 输出统计信息
        print("\n作业提交情况统计:")
        print(f"总学生数: {report['总学生数']}")
        print(f"实验目录数: {len(report['实验目录'])}")
        print("\n实验目录列表:")
        for exp in report['实验目录']:
            print(f"- {exp}")
        print(f"\n详细报告已保存到: {report_path}")

    except Exception as e:
        logger.error(f"检查过程中出错: {str(e)}")
        print(f"错误: {str(e)}")
        sys.exit(1)

if __name__ == "__main__":
    # 设置默认的输入输出目录
    if len(sys.argv) == 1:
        sys.argv.extend([
            r"G:\OneDrive\05Projects\homework\studentselectedcoursebook.xlsx",  # Excel文件路径
            r"C:\Users\dlfan\Desktop\实习报告",       # 作业目录
            r"C:\Users\dlfan\Desktop\实习报告"         # 输出目录
        ])
    main() 